package com.huike.review.controller;

import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @PostMapping("/saveData")
    public int insert(@RequestBody Review review) {
        return reviewService.insert(review);
    }

    @GetMapping("/saveData/{name}/{age}/{sex}")
    public int insertData(@PathVariable("name") String name,
                          @PathVariable("age") int age,
                          @PathVariable("sex") String sex) {
        Review r = new Review();
        r.setAge(age);
        r.setName(name);
        r.setSex(sex);
        return reviewService.insert(r);
    }

    @DeleteMapping("/remove/{id}")
    public int deleteById(@PathVariable("id") Long id) {
        return reviewService.deleteById(id);
    }

    @PostMapping("/update")
    public void updateById(@RequestBody Review review) {
        reviewService.updateById(review);
    }

    @GetMapping("/getById")
    public Review selectById(Long id) {
        return reviewService.selectById(id);
    }

    @GetMapping("/getDataByPage")
    public List<Review> selectPage(int pageNum, int pageSize) {
        return reviewService.selectPage(pageNum, pageSize);
    }
}
